package com.eric.flowabledemo.util;

import org.springframework.beans.BeansException;
import org.springframework.context.*;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

import java.util.Locale;

@Component
public class MessageSourceUtils implements ApplicationContextAware {

    private static MessageSource messageSource;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        messageSource = applicationContext.getBean(MessageSource.class);
    }

    public static String getMessage(String s, @Nullable Object[] objects, @Nullable String s1, Locale locale) {
        return messageSource.getMessage(s, objects, s1, locale);
    }

    public static String getMessage(String s, @Nullable Object[] objects, Locale locale) throws NoSuchMessageException {
        return messageSource.getMessage(s, objects, locale);
    }

    public static String getMessage(MessageSourceResolvable messageSourceResolvable, Locale locale) throws NoSuchMessageException {
        return messageSource.getMessage(messageSourceResolvable, locale);
    }
}
